# coding: utf-8
from common import BaseAPI, Timestamp, cfg
from requests_toolbelt import MultipartEncoder


class UploadStudyRecordAPI(BaseAPI):
    @classmethod
    def begin(cls):
        url = '/sias/Student/Course/UploadStudyRecordBegin'
        params = {
            '_t': Timestamp.now_ms(),
        }
        payload = {
            "classId": "13",
            "courseId": "144",
            "contentId": "kcjs_1_1",
            "contentType": 11,
            "periodId": "24",
            "position": 0,
            "detectId": None
        }
        headers = {'cookie': cfg.get(cfg.cookie)}
        return cls.post(url, params=params, json=payload, headers=headers)

    @classmethod
    def continue_(cls):
        url = '/sias/Student/Course/UploadStudyRecordContinue'
        params = {
            '_t': Timestamp.now_ms(),
        }
        headers = {'cookie': cfg.get(cfg.cookie)}
        multipart_data = MultipartEncoder(fields={})
        headers = {
            'Content-Type': multipart_data.content_type,
            'Referer': ''
        }
        payload = {}
        return cls.post(url, params=params, json=payload, headers=headers, data=multipart_data)
